home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / java / lang / ProcessInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  1.6 KB  |  105 lines

  1. package java.lang;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6. import java.io.PipedInputStream;
  7. import java.io.PipedOutputStream;
  8. import java.util.Vector;
  9.  
  10. class ProcessInputStream extends PipedInputStream implements Runnable {
  11.    InputStream ins;
  12.    OutputStream outs;
  13.    // $FF: renamed from: p java.lang.UNIXProcess
  14.    UNIXProcess field_0;
  15.    byte[] writeBuf;
  16.    boolean chaining;
  17.    int inPos;
  18.    Vector chain;
  19.  
  20.    ProcessInputStream(UNIXProcess var1, PipedOutputStream var2, InputStream var3) throws IOException {
  21.       super(var2);
  22.       this.field_0 = var1;
  23.       this.outs = var2;
  24.       this.ins = var3;
  25.       this.writeBuf = null;
  26.       this.chaining = false;
  27.       this.inPos = 0;
  28.       this.chain = new Vector();
  29.    }
  30.  
  31.    protected synchronized void receive(int var1) throws IOException {
  32.       if (this.chaining) {
  33.          if (this.inPos == 1024) {
  34.             this.writeBuf = new byte[1024];
  35.             this.chain.addElement(this.writeBuf);
  36.             this.inPos = 0;
  37.          }
  38.  
  39.          this.writeBuf[this.inPos++] = (byte)var1;
  40.       } else {
  41.          super.receive(var1);
  42.          if (super.in == super.out) {
  43.             this.inPos = 0;
  44.             this.chaining = true;
  45.             this.writeBuf = new byte[1024];
  46.             this.chain.addElement(this.writeBuf);
  47.          }
  48.  
  49.       }
  50.    }
  51.  
  52.    public synchronized int read() throws IOException {
  53.       if (!this.chaining) {
  54.          return super.read();
  55.       } else {
  56.          if (super.in == -1 && this.chain.size() != 0) {
  57.             super.buffer = (byte[])this.chain.elementAt(0);
  58.             this.chain.removeElementAt(0);
  59.             super.in = super.out = 0;
  60.             if (this.chain.size() == 0) {
  61.                if (this.inPos == 0) {
  62.                   super.in = -1;
  63.                } else if (this.inPos == 1024) {
  64.                   super.in = 0;
  65.                } else {
  66.                   super.in = this.inPos;
  67.                }
  68.  
  69.                this.chaining = false;
  70.             }
  71.          }
  72.  
  73.          return super.read();
  74.       }
  75.    }
  76.  
  77.    public int available() throws IOException {
  78.       return super.available() + 1024 * this.chain.size();
  79.    }
  80.  
  81.    public void run() {
  82.       byte[] var1 = new byte[512];
  83.  
  84.       while(true) {
  85.          try {
  86.             int var2;
  87.             if ((var2 = this.ins.read(var1)) < 0) {
  88.                break;
  89.             }
  90.  
  91.             this.outs.write(var1, 0, var2);
  92.          } catch (IOException var4) {
  93.             break;
  94.          }
  95.       }
  96.  
  97.       try {
  98.          this.outs.close();
  99.       } catch (IOException var3) {
  100.       }
  101.  
  102.       this.field_0.decrNumReaders();
  103.    }
  104. }
  105.